# 写一个函数 myrange 实现和range 一样的功能， 但返回列表
#
#
# def myrange(start, stop=None, step=1):
#     if stop == None:  # 这是一个参数
#         return list(range(0, start))
#     ...
#     此处自己完成
#
#
# for x in myrange(4):
#     print(x)  # 0, 1, 2, 3
#
# for x in myrange(3, 6):
#     print(x)  # 3, 4, 5
# for x in myrange(1, 10, 2):
#     print(x)  # 1, 3, 5, 7, 9



def myrange(start, stop=None, step=None):
    # 方法2
    if stop is None:
        stop = start
        start = 0
    if step is None:
        step = 1
    L = []
    i = start
    if step > 0:  # step 大于零时
        while i < stop:
            L.append(i)
            i += step
    else:  # step 小于零时
        while i > stop:
            L.append(i)
            i += step
    return L  #         课间休息： 10：10 回来

    # 方法1
    # if stop is None:  # 这是一个参数
    #     return list(range(0, start))
    # else:
    #     L = []
    #     i = start
    #     while i < stop:
    #         L.append(i)
    #         i += step
    #     return L

for x in myrange(4):
    print(x, end=' ')  # 0, 1, 2, 3
print()

for x in myrange(3, 6):
    print(x, end=' ')  # 3, 4, 5
print()

for x in myrange(1, 10, 2):
    print(x, end=' ')  # 1, 3, 5, 7, 9
print()

for x in myrange(10, 1, -2):
    print(x, end=' ')  # 10 8 6 4 2
print()

